package cn.hh.controller;

import cn.hh.course.domain.Course;
import cn.hh.god.domain.Buy;
import cn.hh.service.ICourseService;
import cn.hh.util.AjaxResule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private ICourseService courseService;

    @PostMapping("/save")
    public AjaxResule save(@RequestBody Course course){
        try {
            courseService.save(course);
            return new AjaxResule();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @GetMapping("/{id}")
    public Course getById(@PathVariable("id") Long id){
        return courseService.getById(id);
    }

    // 根据
    @PostMapping("update")
    public void updateById(@RequestBody Buy buy){
        courseService.updateById(buy);
    }
}
